home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0151_Enhancement for Commanche Graphics.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  4KB  |  117 lines

  1. {
  2. > Can someone explain the details of how to make game graphics
  3. > like   in commanche over kill ?    (3d amazing graphics)
  4.  
  5. Sean was the first one to post such a routine here. Someone else made a
  6. realy stunning fix for it. I can't recall his name though
  7. (he was/is Russian). Here's the source:
  8.  
  9. - Bas Van Gaalen
  10. }
  11. uses crt;
  12.  
  13. type lrgarr = array[0..65534]of byte;
  14.  
  15. const
  16.  pal : array[1..384]of byte =
  17.  (0,0,0,48,48,48,1,0,43,1,3,43,2,5,44,2,7,44,3,9,45,4,11,46,5,13,47,6,15,48,
  18.   7,17,49,8,19,50,9,21,51,10,22,52,11,24,52,12,26,54,13,28,54,14,30,56,15,32,
  19.   56,16,34,58,17,34,58,17,36,58,18,38,60,19,40,60,20,42,62,21,44,62,10,31,0,
  20.   11,31,0,11,31,1,11,32,1,12,32,1,12,32,2,12,33,2,13,33,2,14,33,3,15,33,3,15,
  21.   34,3,15,34,4,15,35,4,16,35,4,16,35,5,16,36,5,17,36,5,17,36,6,18,37,6,18,38,
  22.   7,19,38,8,20,39,8,20,40,9,21,40,10,22,41,10,22,42,11,23,42,12,24,43,12,24,
  23.   44,13,25,44,14,25,45,14,26,46,15,27,46,16,27,47,17,28,47,18,28,48,19,29,49,
  24.   19,30,49,20,30,50,21,31,51,21,32,51,22,32,52,23,33,53,23,34,53,24,34,54,25,
  25.   35,55,25,36,55,26,36,56,27,37,57,27,38,57,27,39,57,27,41,57,27,42,57,27,43,
  26.   57,27,44,57,27,45,57,27,46,57,27,47,57,27,49,57,27,50,57,27,51,57,27,52,57,
  27.   27,53,57,27,55,57,27,56,57,27,57,57,27,58,57,27,58,57,26,58,57,25,58,57,24,
  28.   58,56,23,58,55,22,58,54,20,58,53,19,58,51,18,58,50,17,58,50,16,58,49,15,58,
  29.   48,14,58,47,13,58,46,12,58,45,11,58,44,11,58,44,10,58,43,10,58,42,9,57,41,
  30.   8,57,40,8,56,39,7,56,38,6,55,37,5,55,35,4,54,33,4,54,31,2,32,32,32,63,63,63,
  31.   63,63,63,63,63,63,63,63,63,48,48,48,63,63,63,63,63,63);
  32.  
  33. var
  34.  ctab,stab:array[0..360] of integer;
  35.  mp,scr : ^lrgarr;
  36.  rng : array[0..320]of byte;
  37.  dir,i,x,y : integer;
  38.  
  39. function ncol(mc,n,dvd : integer): integer;
  40. var loc : integer;
  41. begin
  42.  loc:=(mc+n-random(2*n)) div dvd; ncol:=loc;
  43.  if loc>250 then ncol:=250; if loc<5 then ncol:=5
  44. end;
  45.  
  46. procedure plasma(x1,y1,x2,y2 : word);
  47. var xn,yn,dxy,p1,p2,p3,p4 : word;
  48. begin
  49.  if (x2-x1<2) and (y2-y1<2) then EXIT;
  50.  p1:=mp^[256*y1+x1]; p2:=mp^[256*y2+x1]; p3:=mp^[256*y1+x2];
  51.  p4:=mp^[256*y2+x2]; xn:=(x2+x1) shr 1; yn:=(y2+y1) shr 1;
  52.  dxy:=5*(x2-x1+y2-y1) div 3;
  53.  if mp^[256*y1+xn]=0 then mp^[256*y1+xn]:=ncol(p1+p3,dxy,2);
  54.  if mp^[256*yn+x1]=0 then mp^[256*yn+x1]:=ncol(p1+p2,dxy,2);
  55.  if mp^[256*yn+x2]=0 then mp^[256*yn+x2]:=ncol(p3+p4,dxy,2);
  56.  if mp^[256*y2+xn]=0 then mp^[256*y2+xn]:=ncol(p2+p4,dxy,2);
  57.  mp^[256*yn+xn]:=ncol(p1+p2+p3+p4,dxy,4);
  58.  plasma(x1,y1,xn,yn); plasma(xn,y1,x2,yn);
  59.  plasma(x1,yn,xn,y2); plasma(xn,yn,x2,y2);
  60. end;
  61.  
  62. procedure draw(xp,yp,dir : integer);
  63. var z,zobs,ix,iy,iy1,iyp,ixp,x,y,s,csf,snf,mpc,i,j : integer;
  64. begin
  65.  fillchar(rng,sizeof(rng),200);  zobs:=100+mp^[256*yp+xp];
  66.  csf:=round(256*cos(dir/180*pi)); snf:=round(256*sin(dir/180*pi));
  67.  fillchar(scr^,64000,0);
  68.  for iy:=yp to yp+55 do
  69.  begin
  70.   iy1:=1+2*(iy-yp); s:=4+300 div iy1;
  71.   for ix:=xp+yp-iy to xp-yp+iy do
  72.   begin
  73.    ixp:=xp+((ix-xp)*csf+(iy-yp)*snf) shr 8;
  74.    iyp:=yp+((iy-yp)*csf-(ix-xp)*snf) shr 8;
  75.    x:=160+360*(ix-xp) div iy1;
  76.    if (x>=0) and (x+s<=318) then
  77.    begin
  78.     z:=mp^[iyp shl 8+ixp]; mpc:=z shr 1;
  79.     if z<47 then z:=46;  y:=100+(zobs-z)*30 div iy1;
  80.     if (y<=199) and (y>=0) then
  81.      for j:=x to x+s do
  82.      begin
  83.       for i:=y to rng[j] do scr^[320*i+j]:=mpc;
  84.       if y<rng[j] then rng[j]:=y
  85.      end;
  86.    end;
  87.   end;
  88.  end;
  89.  move(scr^,mem[$a000:0],64000);
  90. end;
  91.  
  92. begin
  93.  randomize; x:=0; y:=0; dir:=0; new(mp); fillchar(mp^,65535,0);
  94.  new(scr); mp^[$0000]:=128; plasma(0,0,256,256);
  95.  asm xor ax,ax; mov al,$13; int $10; end;
  96.  port[$3c8]:=0; for i:=1 to 384 do port[$3c9]:=pal[i];
  97.  repeat
  98.   dir:=dir mod 360;
  99.   draw(x,y,dir);
  100.   case readkey of
  101.    #0:case readkey of
  102.      #75:dec(dir,10);
  103.      #77:inc(dir,10);
  104.      #72:begin
  105.        y:=y+round(5*cos(dir/180*pi));
  106.        x:=x+round(5*sin(dir/180*pi));
  107.      end;
  108.      #80:begin
  109.        y:=y-round(5*cos(dir/180*pi));
  110.        x:=x-round(5*sin(dir/180*pi));
  111.      end;
  112.    end;
  113.    #27:begin asm xor ax,ax; mov al,$3; int $10; end; HALT end
  114.   end
  115.  until false;
  116. end.
  117.